﻿using FoodModel;
using J.FoodRepository.InterFace;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace J.FoodRepository.Impl
{
    public class TableNumRepository : BackRepository<TableNumModel>, ITableNumRepository
    {
        public TableNumRepository(ISqlSugarClient db) : base(db)
        {
        }
        /// <summary>
        /// 桌号添加
        /// </summary>
        /// <returns></returns>
        public async Task<int> NumAdd(TableNumModel model)
        {
            return await base.AddAsync(model);
        }
        /// <summary>
        /// 桌号反填
        /// </summary>
        /// <returns></returns>
        public async Task<TableNumModel> NumBack(int id)
        {
            return await base.GetModelAsync(id);
        }
        /// <summary>
        /// 桌号批量删除
        /// </summary>
        /// <returns></returns>
        public async Task<int> NumDelete(string id)
        {
            var ids = id.Split(',');
            var list = await base.GetAsync(propa => ids.Contains(propa.TableNumId.ToString()));
            foreach (var item in list)
            {
                base.DeleteAsync(item.TableNumId);
            }
            return list.Count;
        }
        /// <summary>
        /// 桌号显示id显示
        /// </summary>
        /// <returns></returns>
        public async Task<List<TableNumModel>> NumIdShow(string? id)
        {
            var ids = id.Split(',');
            var list = await base.GetAsync(propa => ids.Contains(propa.TableNumId.ToString()));

            return list.ToList(); 
        }

        /// <summary>
        /// 桌号批量修改状态
        /// </summary>
        /// <returns></returns>
        public async Task<int> NumplUpDate(string id)
        {
            var ids = id.Split(',');
            var list = await base.GetAsync(propa => ids.Contains(propa.TableNumId.ToString()));
            foreach (var item in list)
            {
                if (item.Enable == true)
                {
                    item.Enable = false;
                }
                else
                {
                    item.Enable = true;
                }
                await base.UpdateAsync(item);

            }
            return list.Count;
        }

        /// <summary>
        /// 桌号显示
        /// </summary>
        /// <returns></returns>
        public async Task<List<TableNumModel>> NumShow()
        {
            return await base.GetAllAsync();

        }
        /// <summary>
        /// 桌号修改
        /// </summary>
        /// <returns></returns>
        public async Task<int> NumUpdate(TableNumModel model)
        {
            return await base.UpdateAsync(model);
        }
    }
}
